package com.ruoyi.slope.ai.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.slope.ai.domain.SlopeAiCrackMonitoring;
import com.ruoyi.slope.ai.service.ISlopeAiCrackMonitoringService;
import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 边坡裂缝目标识别监测Controller
 * 
 * @author ruoyi
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/ai/aiCrack")
public class SlopeAiCrackMonitoringController extends BaseController
{
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeAiCrackMonitoringService slopeAiCrackMonitoringService;

    /**
     * 查询边坡裂缝目标识别监测列表
     */
    @PreAuthorize("@ss.hasPermi('ai:aiCrack:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeAiCrackMonitoring slopeAiCrackMonitoring)
    {
        startPage();
        List<SlopeAiCrackMonitoring> list = slopeAiCrackMonitoringService.selectSlopeAiCrackMonitoringList(slopeAiCrackMonitoring);
        return getDataTable(list);
    }

    /**
     * 导出边坡裂缝目标识别监测列表
     */
    @PreAuthorize("@ss.hasPermi('ai:aiCrack:export')")
    @Log(title = "边坡裂缝目标识别监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeAiCrackMonitoring slopeAiCrackMonitoring)
    {
        List<SlopeAiCrackMonitoring> list = slopeAiCrackMonitoringService.selectSlopeAiCrackMonitoringList(slopeAiCrackMonitoring);
        ExcelUtil<SlopeAiCrackMonitoring> util = new ExcelUtil<SlopeAiCrackMonitoring>(SlopeAiCrackMonitoring.class);
        String path = util.exportExcel(response, list, "边坡裂缝目标识别监测数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取边坡裂缝目标识别监测详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:aiCrack:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slopeAiCrackMonitoringService.selectSlopeAiCrackMonitoringById(id));
    }

    /**
     * 新增边坡裂缝目标识别监测
     */
    @PreAuthorize("@ss.hasPermi('ai:aiCrack:add')")
    @Log(title = "边坡裂缝目标识别监测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeAiCrackMonitoring slopeAiCrackMonitoring)
    {
        return toAjax(slopeAiCrackMonitoringService.insertSlopeAiCrackMonitoring(slopeAiCrackMonitoring));
    }

    /**
     * 修改边坡裂缝目标识别监测
     */
    @PreAuthorize("@ss.hasPermi('ai:aiCrack:edit')")
    @Log(title = "边坡裂缝目标识别监测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeAiCrackMonitoring slopeAiCrackMonitoring)
    {
        return toAjax(slopeAiCrackMonitoringService.updateSlopeAiCrackMonitoring(slopeAiCrackMonitoring));
    }

    /**
     * 删除边坡裂缝目标识别监测
     */
    @PreAuthorize("@ss.hasPermi('ai:aiCrack:remove')")
    @Log(title = "边坡裂缝目标识别监测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slopeAiCrackMonitoringService.deleteSlopeAiCrackMonitoringByIds(ids));
    }
}
